package Demo001;

public class Demo04 {
    private int id=-1;
    private String name="xiongda";
    private int age=18;

//    封装（setter/getter原理：获取属性并判断）
//    1.先将属性私有化private
//    2.生成set/get方法
//    3.给出判断条件

    public void setName(String name) {
        this.name = name;
    }

    public void setId(int id){
        if(id <= 0){
            System.out.println("ID为负数，为您重置为1!!");
            this.id=1;
        }
        else{
            this.id=id;
        }
    }

    public void setAge(int age){
        this.age=age;
    }

    public String getName() {
        return name;
    }

    public int getId(){
        return id;
    }

    public int getAge(){
        return age;
    }

    public void show01(){
        System.out.println(this.id+" "+this.name+" "+this.age);
    }

    public void show02(){
        System.out.println(this.id);
    }

    public void show03(){
        System.out.println(age);
    }

    public void show04(){
        System.out.println(name);
    }

    public static void main(String[] args){
        Demo04 demo = new Demo04();
        demo.show01();

        demo.setName("xionger");
        demo.setId(-6);
        demo.setAge(17);
        demo.show02();
        demo.show03();
        demo.show04();
    }
}
